import Vue from 'vue'
import Vuex from 'vuex'
import router from "@/router";
Vue.use(Vuex)


export default new Vuex.Store({
  state: {
    userInfo: {},
    isLogin: false,
    menuList:[],
    systemMenu:null,
    doneNum:'',
    unDoneNum:'',
    unReadNum:'',
  },
  getters: {
    userInfo: state => state.userInfo,
    isLogin: state => state.isLogin,
    menuList: state => state.menuList,
    systemMenu:state=>state.systemMenu,
    doneNum: state => state.doneNum,
    unDoneNum: state => state.unDoneNum,
    unReadNum: state => state.unReadNum,
  },
  mutations: {
    SET_USERINFO(state, payload) {
      state.userInfo = payload
    },
    SET_ISLOGIN(state, payload) {
      if (payload == false) {
        state.userInfo = {}
      }
      state.isLogin = payload
    },
    SET_MENU_LIST(state, payload) {
      state.menuList = payload
      state.menuList.forEach(x=>{
        if(['user','org','role','dict','log'].includes(x.name)){
          state.systemMenu = x
        }
      })
      state.menuList = state.menuList.filter(x=>{
        return x.name !==  state.systemMenu.name
      })
    },
    SET_UN_READ(state, payload) {
      state.unReadNum = payload
    },
    SET_DONE_NUM(state, payload) {
      state.unDoneNum = payload.unDoneNum
      state.doneNum = payload.doneNum
    },
  },
  actions: {
    setUserInfo({commit}, payload) {
      commit('SET_USERINFO', payload)
    },
    setIsLogin({commit}, payload) {
      commit('SET_ISLOGIN', payload)
    },
    setMenuList({commit}, payload) {
      commit('SET_MENU_LIST', payload)
    },
    setDoneNum({commit}, payload) {
      commit('SET_DONE_NUM', payload)
    },
    setUnRead({commit}, payload) {
      commit('SET_UN_READ', payload)
    },
  },
  modules: {}
})